package com.example.appstudy2405;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class BitCatP14EditView extends AppCompatActivity implements View.OnClickListener {

    private EditText etName, etPwd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bit_cat_p14_edit_view);
        etName = findViewById(R.id.et_uname);
        etPwd = findViewById(R.id.et_pwd);
        findViewById(R.id.bt_login).setOnClickListener(this);
    }

    public void login(View view) {
        String uname = etName.getText().toString().trim();
        String upwd = etPwd.getText().toString().trim();
        if (TextUtils.isEmpty(uname) || TextUtils.isEmpty(upwd)) {
            Toast.makeText(this, "User name or User password Couldn't empty!!", Toast.LENGTH_SHORT).show();
            return;
        }

        // 校验密码框的位数为6-12位
        if (upwd.length() < 6 || upwd.length() > 12) {
            Toast.makeText(this, "校验密码框的位数为6-12位", Toast.LENGTH_SHORT).show();
            return;
        }
        Toast.makeText(this, "Login success!", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.bt_login) {
            login(view);
        }
    }
}